﻿using nplJobsCommon.Common;
using nplJobsCommon.JobSeeker;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nplJobsDAL.Select
{
    public class SelectJobSeeker : DataAccessBase
    {
        public Guid JobSeekerID { get; set; }

        public SelectJobSeeker()
        {
            StoredProcedureName = StoredProcedure.Name.spSelectJobSeekerByID.ToString();
        }
        #region GetJobSeeker
        public List<JobSeeker> GetJobSeeker()
        {
            DataBaseHelper dbHelper;
            DataSet dsJobSeeker;

            List<JobSeeker> jobSeekers = new List<JobSeeker>();

            try
            {
                SelectJobSeekerParameters selectJobSeekerParameters = new SelectJobSeekerParameters(this.JobSeekerID);
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dbHelper.Parameters = selectJobSeekerParameters.Parameters;
                dsJobSeeker = dbHelper.Run(base.ConnectionString, dbHelper.Parameters);
                jobSeekers = GetList(dsJobSeeker);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return jobSeekers;
        }
        #endregion

        #region SQL parameters for selecting job seeker by id
        public class SelectJobSeekerParameters
        {
            public int CkeckUnique;
            private SqlParameter[] _parameters;

            public SelectJobSeekerParameters(Guid jobSeekerID)
            {
                this.JobSeekerID = jobSeekerID;
                Build();
            }

            #region spAddContact parameters
            /*
         
         */
            #endregion

            private void Build()
            {
                SqlParameter[] parameters = 
                {
                    new SqlParameter("@JobSeekerID", JobSeekerID),
                };

                Parameters = parameters;
            }

            public Guid JobSeekerID { get; set; }

            public SqlParameter[] Parameters
            {
                get { return _parameters; }
                set { _parameters = value; }
            }
        }
        #endregion

        #region GetList
        private List<JobSeeker> GetList(DataSet dsJobSeeker)
        {
            List<JobSeeker> jobSeeker = new List<JobSeeker>();
            try
            {
                jobSeeker = (from n in dsJobSeeker.Tables[0].AsEnumerable()
                             select new JobSeeker
                                {
                                    JobSeekerID = n.Field<Guid>("JobSeekerID"),
                                    FirstName = n.Field<string>("FirstName"),
                                    LastName = n.Field<string>("LastName"),
                                    Email = n.Field<string>("Email"),
                                    AlternativeEmail = n.Field<string>("AlternativeEmail"),
                                    DOB = n.Field<DateTime>("DOB"),
                                    GenderID = n.Field<int>("GenderID"),
                                    MaritalStatusID = n.Field<int>("MaritalStatusID"),
                                    NationalityID = n.Field<int>("NationalityID"),
                                    PostalAddress = n.Field<string>("PostalAddress"),
                                    HomePhone = n.Field<string>("HomePhone"),
                                    MobilePhone = n.Field<string>("MobilePhone"),
                                    Photo = n.Field<string>("Photo"),
                                    Resume = n.Field<string>("Resume"),
                                    IsDeleted = n.Field<bool>("IsDeleted"),
                                    AboutMe = n.Field<string>("AboutMe"),
                                    CreatedOn = n.Field<DateTime>("CreatedOn"),
                                    Modifiedon = n.Field<DateTime>("Modifiedon"),
                                    Skills = n.Field<string>("Skills"),
                                    Qualifications = n.Field<string>("Qualifications"),
                                    ExpectedSalaryID = n.Field<int>("ExpectedSalaryID"),
                                    PresentSalaryID = n.Field<int>("PresentSalaryID"),
                                    CountryID = n.Field<int?>("CountryID"),
                                    DivisionID = n.Field<int?>("DivisionID"),
                                    DistrictID = n.Field<int?>("DistrictID"),
                                    CityID = n.Field<int?>("CityID"),
                                    PresentSalaryRange = n.Field<string>("PresentSalaryRange"),
                                    ExpectedSalaryRange = n.Field<string>("ExpectedSalaryRange"),
                                    City = n.Field<string>("CityName"),
                                    District = n.Field<string>("District"),
                                    Division = n.Field<string>("Division"),
                                    Gender = n.Field<string>("GenderName"),
                                    MaritalStatus = n.Field<string>("MaritalStatus"),
                                    Nationality = n.Field<string>("NationalityName"),
                                    Country = n.Field<string>("Country"),


                                }).ToList();

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }

            return jobSeeker;

        }
        #endregion

    }
}

